<?php $path = base_url().'public/frontend/';?>
<div class="features_items">
    <h2 class="title text-center">Features Items</h2>
    <?php foreach($products as $product) { ?>
    <div class="col-sm-4">
        <div class="product-image-wrapper">
            <div class="single-products">
                <div class="productinfo text-center" style="height: 395px">
                    <img src="<?php
                    if (strpos($product['url_image'], '//'))
                        echo $product['url_image'];
                    else echo base_url().'public/images/'.$product['url_image']; ?>" style="width: 255px; height: 237px" alt="" />
                    <?php if (!$product['new_price']){ ?>
                        <h2>$<?php echo $product["unit_price"] ?></h2>
                    <?php } elseif ($product['new_price']){ ?>
                        <span style='color:#696763;text-decoration:line-through'>
                          <span style="color: #FE980F;
                                font-family: 'Roboto', sans-serif;
                                font-size: 24px;
                                font-weight: 700;">$<?php echo $product["unit_price"] ?></span>
                        </span>
                        <h2 style="margin-top: 0px">$<?php echo $product['new_price'] ?></h2>
                    <?php } ?>
                    <p><?php  echo substr($product["product_name"], 0, 30)?></p>
                    <a class="btn btn-default add-to-cart addCart_<?php echo $product["product_id"] ?>" data-id="<?php echo $product["product_id"] ?>"><i class="fa fa-shopping-cart"></i><span>Add to cart</span></a>
                </div>
                <div class="product-overlay">
                    <div class="overlay-content">
                        <img src="<?php
                        if (strpos($product['url_image'], '//'))
                            echo $product['url_image'];
                        else echo base_url().'public/images/'.$product['url_image']; ?>" style="width: 256px;" alt="" />
                        <a href="<?php echo base_url() ;?>frontend/product_detail/viewProductDetail/<?php echo $product["product_id"] ?>"><h2>View Detail</h2></a>
                        <p><?php echo $product["product_name"] ?></p>
                        <a class="btn btn-default add-to-cart addCart_<?php echo $product["product_id"] ?>"  data-id="<?php echo $product["product_id"] ?>"><i class="fa fa-shopping-cart"></i><span>Add to cart</span></a>
                    </div>
                </div>
            </div>
            <div class="choose">
                <ul class="nav nav-pills nav-justified">
<!--                    <li><a href="#"><i class="fa fa-plus-square"></i>Add to wishlist</a></li>-->
<!--                    <li><a href="#"><i class="fa fa-plus-square"></i>Add to compare</a></li>-->
                </ul>
            </div>
        </div>
    </div>
    <?php } ?>
    <div style="text-align: center">
    <?php
        if ($page!=1) echo "<a href='?p=".($page-1)."'><i style='background: #FE980F;
                        color: #FFFFFF;
                        font-size: 15px;
                        padding: 5px 10px;display: inline-block;
                        font-family: FontAwesome;
                        font-style: normal;
                        font-weight: normal;
                        line-height: 1;
                        -webkit-font-smoothing: antialiased;'><</i></a>";
        for($i=1;$i<=$page_num;++$i){
            if ($i!=$page) echo "<a style='margin-left: 5px;' href='?p=$i".((isset($query) ? "&q=".$query : ""))."'><i style='background: #FE980F;
                    color: #FFFFFF;
                    font-size: 15px;
                    padding: 5px 10px;display: inline-block;
                    font-family: FontAwesome;
                    font-style: normal;
                    font-weight: normal;
                    line-height: 1;
                    -webkit-font-smoothing: antialiased;'>$i</i></a>";
                                    else echo "<a style='margin-left: 5px;'><i style='background: #CCCCCC;
                    color: #FFFFFF;
                    font-size: 15px;
                    padding: 5px 10px;display: inline-block;
                    font-family: FontAwesome;
                    font-style: normal;
                    font-weight: normal;
                    line-height: 1;
                    -webkit-font-smoothing: antialiased;'>$i</i></a>";
        }
        if ($page!=$page_num) echo "<a style='margin-left: 5px;' href='?p=".(($page+1).(isset($query) ? "&q=".$query : ""))."'><i style='background: #FE980F;
                        color: #FFFFFF;
                        font-size: 15px;
                        padding: 5px 10px;display: inline-block;
                        font-family: FontAwesome;
                        font-style: normal;
                        font-weight: normal;
                        line-height: 1;
                        -webkit-font-smoothing: antialiased;'>></i></a>";
        ?>
    </div>
<script>
    $('.add-to-cart').click(function(){
        quantity = 1;
        pid = $(this).attr('data-id');

        $.post('<?php echo base_url() ;?>frontend/purchase/add_cart',{
            pid : pid,
            quantity : quantity
        }).done(function(data){
            if(parseInt(data) ==1){
                $('.addCart_'+pid).find('span').text('Added to cart');
            }
            else alert('Please login first')
        })
    })
</script>
